<?php

/**
 * @application Automatical Judging System
 * @author deltamaster
 * @copyright Softrank Research Center
 * @version 2.0.0.0
 */

require_once "./include/common.inc.php";

if ($sys_uid)
{
    showmessage("Logged in already.", 'index.php');
}

if (submitcheck('registersubmit'))
{
    if (VerifyUsername($_POST['inputusername']) && VerifyPassword($_POST['inputpassword']) &&
        VerifyRealName($_POST['inputrealname']) && VerifyEmail($_POST['inputemail']) &&
        VerifyMobile($_POST['inputmobile']) && VerifyStudentId($_POST['studentid']))
    {
        if ($_POST['inputpassword'] == $_POST['confirmpassword'])
        {
            $inputpassword = md5($_POST['inputpassword']);
            $query = $db->query("INSERT INTO `{$tablepre}user` (`username`, `password`, `email`, `mobile`, `realname`, `studentid`) VALUES ('{$_POST['inputusername']}', '{$inputpassword}', '{$_POST['inputemail']}', '{$_POST['inputmobile']}', '{$_POST['inputrealname']}', '{$_POST['studentid']}')");
            $last_insert_id = $db->insert_id();
            $query = $db->query("insert into `{$tablepre}record` (`uid`, `pid`, `type`, `event`) values ('{$last_insert_id}', '0', 'notice', '{$lang['welcome']}')");
            showmessage($lang['register_success'], 'login.php');
        }
    }
    showmessage($lang['register_fail'], 'register.php');
}


include template('register');

?>